<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>数据源配置</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/js/themes/default/easyui.css" />
		<link rel="stylesheet" type="text/css"
			href="${pageContext.request.contextPath}/js/themes/icon.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath}/homepages/css/main.css"
			type="text/css" />
		<link rel="stylesheet" href="${pageContext.request.contextPath}/css/ainit.css" type="text/css"/>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/jquery-1.4.4.min.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/jquery.easyui.min.1.2.2.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/homepages/js/forms.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/js/jquery.ainit-1.0.0.js"></script>
		<script type="text/javascript">
			$(function(){
				$('#pages').load('${pageContext.request.contextPath}/sys/inputForms',
				{'configId':'CreateDS'}); 
			});
			
			function saveSqlText(){
				$.ajax({
					type:'post',
					url:'${pageContext.request.contextPath}/sys/saveSql',
					data:$('#INFO_FORM').serialize(),
					success:function(data){
						var qou = data.extendinfo;
						$('#loadQueryCol').show();
						var lastIndex;
						$('#loadQueryCol').datagrid({
		 			 		iconCls:'icon-save',
		 			 		width:'800',
							nowrap: false,
							striped: true,				 
							collapsible:true,
							autoRowHeight: false,		
							sortOrder: 'desc',
							remoteSort: false,
							fitColumns:true,
							columns:[[]],
							pagination:true,
							rownumbers:true,
							singleSelect:true,
							onDblClickRow:function(rowIndex){
								if (lastIndex != rowIndex){
									$('#loadQueryCol').datagrid('endEdit', lastIndex);
									$('#loadQueryCol').datagrid('beginEdit', rowIndex);
								}
								lastIndex = rowIndex;
							},
							onAfterEdit:function(rowIndex,rowData,changes){
								var dsId = rowData.DS_ID;
								var name = rowData.NAME;
								var cname=changes.COLN_NAME;
								var inputType= changes.INPUTTYPE;
								var ediType = changes.EDITYPE;
								var orderNum = changes.ORDERNUM;
								var firstFlag=changes.FIRSTPAGEFLAG;
								var isShow = changes.ISSHOW;
								var javaProperty= changes.JAVA_PROPERTY;
								var javaPropertyRec=changes.JAVA_PROPERTY_RECORDED;
								endEditorCol(dsId,cname,name,inputType,ediType,orderNum,firstFlag,isShow,javaProperty,javaPropertyRec);
							}
		 			 	});
		 			 	var dataGrid = $('#loadQueryCol');
						var options = {  
								rownumbers: true  
							};
						var columns = new Array();
						for(var i = 0; i < data.columns.length; i++){
							var column = {};
							column.title = data.columns[i].colnName;
							column.field = data.columns[i].name;
							column.width = 180;
							column.sortable = true;
							if(column.field != "DS_ID" && column.field != "NAME"){
								column.editor = 'text';
							}
							columns[i] = column;
						}
						var cc = new Array();
						cc[0] = columns;
						options.columns = (cc);
						dataGrid.datagrid(options);
						dataGrid.datagrid("loadData", data);
						$('#DS001').attr('disabled',true);
						
					}
				})
			}
			
			function endEditorCol(dsId,cname,name,inputType,ediType,orderNum,firstFlag,isShow,javaProperty,javaPropertyRec){
				var config = 'DS_ID='+dsId+',COLN_NAME='+cname+',NAME='+name+',INPUTTYPE='+inputType+',EDITYPE='+ediType+',ORDERNUM='+orderNum+',FIRSTPAGEFLAG='+firstFlag+',ISSHOW='+isShow+',JAVA_PROPERTY='+javaProperty+',JAVA_PROPERTY_RECORDED='+javaPropertyRec;
				$.ajax({
					type:'post',
					url:'${pageContext.request.contextPath}/sys/updateColumns',  
					data:{'sqlParams':parseParams(config.split(',')),'sysTName':'sys_columns'},
					success:function(data){
						//重新更新datagrid中的数据
						$.messager.show({
							title:'结果提示框',
							msg:data.msg,
							showType:'show'
						})
					}
				})
			}
			function endEditor1(dsId,cname,name,inputType,ediType,orderNum,firstFlag,isShow,javaProperty){
				var config = 'DS_ID='+dsId+',COLN_NAME='+cname+',NAME='+name+',INPUTTYPE='+inputType+',EDITYPE='+ediType+',ORDERNUM='+orderNum+',FIRSTPAGEFLAG='+firstFlag+',ISSHOW='+isShow+',JAVA_PROPERTY='+javaProperty;
				$.ajax({
					type:'post',
					url:'${pageContext.request.contextPath}/sys/updateInfo',  
					data:{'sqlParams':parseParams(config.split(',')),'sysTName':'sys_ui_forms_columns'},
					success:function(data){
						$.messager.show({
							title:'结果提示框',
							msg:data.msg,
							showType:'show'
						})
					}
				})
			}
		</script> 
  </head>
  
  <body>
  	<div class="easyui-panel" title="数据源配置">
  		<div id="pages"></div>
  	</div>
  	<div id="loadQueryCol" style="display: none">
  		
  	</div>
  </body>
</html>